package com.wtwd.campus.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.wtwd.campus.dao.ClassesMapper;
import com.wtwd.campus.entity.Classes;
import com.wtwd.campus.entity.ExcelImportStudentInfo;
import com.wtwd.campus.service.ClassesService;
import com.wtwd.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author mjy
 * @date 2021/06/17
 * @description
 */
@Service
public class ClassesServiceImpl implements ClassesService {

    @Autowired
    private ClassesMapper classesMapper;

    @Resource
    private StudentService studentService;

    @Override
    public List<Map<String, Object>> getClassesIdAndClassNameByGradeId(Integer gradeId) {
        return classesMapper.getClassesIdAndClassNameByGradeId(gradeId);
    }

    @Override
    public Classes getClassesInfoByCondition(String orgCode, ExcelImportStudentInfo excelImportStudent) {
        return classesMapper.getClassesInfoByCondition(orgCode, excelImportStudent);
    }

    @Override
    public Classes getClassesByGradeIdAndClassesName(Integer gradeId, String classesName) {
        return new LambdaQueryChainWrapper<>(classesMapper)
                .eq(Classes::getGradeId, gradeId)
                .eq(Classes::getClassesName, classesName)
                .one();

    }

    @Override
    public Classes save(Classes classes) {
        classesMapper.insert(classes);
        return classes;
    }
}
